package org.cyk.dataes

import org.cyk.dataes.model.AlbumListDo
import org.cyk.dataes.model.AlbumPhotoSimp
import org.cyk.dataes.model.UserInfoSimp
import org.junit.jupiter.api.Test
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate
import javax.annotation.Resource

@SpringBootTest(classes = [DataEsApplication::class])
class AlbumListTests {

    @Resource private lateinit var esTemplate: ElasticsearchRestTemplate

    @Test
    fun clear() {
//        esTemplate.indexOps(AlbumListDo::class.java).delete()
        esTemplate.indexOps(AlbumListDo::class.java).create()
        esTemplate.indexOps(AlbumListDo::class.java).putMapping(
            esTemplate.indexOps(AlbumListDo::class.java).createMapping()
        )
    }

    @Test
    fun test1() {
        val o = AlbumListDo(
            id = 1,
            userinfo = UserInfoSimp(
                userId = 1,
                username = "cyk",
                avatar = "http:photo1.com"
            ),
            title = "天气很好的一天",
            content = "早上起来，我要好好学习，然去公园散步~",
            photos = listOf(
                AlbumPhotoSimp(1, "www.photo1"),
                AlbumPhotoSimp(2, "www.photo2")
            )
        )
        val result = esTemplate.save(o)
        println(result)
    }

}